{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3a79ef54-63e6-429f-ba9f-590b736a7f29",
   "metadata": {},
   "source": [
    "# 3.7 张量的幂、指数、对数运算"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c90a18b9-d8e8-431c-856c-35f1e4ed05e1",
   "metadata": {},
   "source": [
    "### 1.任务描述\n",
    "- 创建值为[1,2,3]，类型为float32的张量re1\n",
    "- 创建值为[4,5,6]，类型为float32的张量re2\n",
    "- 求re2的re1次幂，得到张量re3\n",
    "- 取re1的平方，得到张量re4\n",
    "- 取re1的开方，得到张量re5\n",
    "- 对re1取自然底数的幂，得到张量re6\n",
    "- 对re1取自然底数的对数，得到张量re7"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "8d7baa9c-93a2-42f3-a3c1-231cdb587f2d",
   "metadata": {},
   "source": [
    "### 2.知识准备\n",
    "\n",
    "见教程。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74ad989a-9b82-43e1-b841-e74284cd5936",
   "metadata": {},
   "source": [
    "### 3.任务分析\n",
    "\n",
    "TensorFlow的math模块提供了幂数、指数和对数运算功能。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "435c6090-cfda-4f46-a550-22a368e41e4a",
   "metadata": {},
   "source": [
    "### 4.任务实施\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "ec75eb6c-5da3-467d-a471-ca3b47242dd6",
   "metadata": {},
   "source": [
    "执行代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2ae9da58-e339-4d22-9f8d-ca255711d89e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor([1. 2. 3.], shape=(3,), dtype=float32)\n",
      "tf.Tensor([4. 5. 6.], shape=(3,), dtype=float32)\n",
      "tf.Tensor([  4.        24.999998 216.      ], shape=(3,), dtype=float32)\n",
      "tf.Tensor([1. 4. 9.], shape=(3,), dtype=float32)\n",
      "tf.Tensor([1.        1.4142135 1.7320508], shape=(3,), dtype=float32)\n",
      "tf.Tensor([ 2.7182817  7.389056  20.085537 ], shape=(3,), dtype=float32)\n",
      "tf.Tensor([0.        0.6931472 1.0986123], shape=(3,), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "# 创建值为[1,2,3]，类型为float32的张量re1\n",
    "re1=tf.constant([1,2,3],dtype=tf.float32)\n",
    "print(re1)\n",
    "# 创建值为[4,5,6]，类型为float32的张量re2\n",
    "re2=tf.constant([4,5,6],dtype=tf.float32)\n",
    "print(re2)\n",
    "# 求re2的re1次幂，得到张量re3\n",
    "re3=tf.math.pow(re2,re1)\n",
    "print(re3)\n",
    "# 取re1的平方，得到张量re4\n",
    "re4=tf.math.square(re1)\n",
    "print(re4)\n",
    "# 取re1的开方，得到张量re5\n",
    "re5=tf.math.sqrt(re1)\n",
    "print(re5)\n",
    "# 对re1取自然底数的幂，得到张量re6\n",
    "re6=tf.math.exp(re1)\n",
    "print(re6)\n",
    "# 对re1取自然底数的对数，得到张量re7\n",
    "re7=tf.math.log(re1)\n",
    "print(re7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f2c61db-4b69-49f9-9b22-f6d2642a056d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
